<template>
	<view>
		<zero-loading type="circle" v-if="loading"></zero-loading>
		<view class="title "></view>
		<scroll-view scroll-y="true" class="scroll-Y" :style='{ height: scrollHeight }'>
			<view class="flex text-center nav">

				<view :class="TabCur==0?'text-olive cur':'text-grey'" class="cu-item  flex-sub  " @tap="onTabSelect(0)">
					<i class="iconfont icon-house  padding-right-xs"></i>
					<text class=" text-md ">
						单元概览
					</text>
				</view>

				<view :class="TabCur==1?'text-olive cur':'text-grey'" class="cu-item flex-sub  " @tap="onTabSelect(1)">
					<i class="iconfont icon-siweiqi  padding-right-xs"></i>
					<text class=" text-md ">
						栏位
					</text>
				</view>

				<view :class="TabCur==2?'text-olive cur':'text-grey'" class="cu-item flex-sub  " @tap="onTabSelect(2)">
					<i class="iconfont icon-yingjian  padding-right-xs"></i>
					<text class=" text-md ">
						智能终端
					</text>
				</view>

			</view>

			<block v-if="TabCur==0">
				<scroll-view scroll-y="true" class="scroll-Y " :style='{ height: innerScrollHeight }'>
					<view class="cu-bar solid-bottom">
						<view class="action">
							<text class="cuIcon-titles text-olive"></text><text class="text-grey ">概览</text>
						</view>
						<!-- <view class="action">
							<text class="cuIcon-moreandroid text-icon-size text-olive "></text>
						</view> -->
					</view>

					<view class="grid col-2 padding-xs">
						<view class="padding-xs">
							<view class="bg-pannel padding-sm radius  shadow" hover-class="opcity"
								hover-stay-time="150">
								<view class="flex ">
									<view class="flex-sub flex align-center ">
										<i class="iconfont icon-food text-sl text-grey"></i>
									</view>
									<view class="flex-twice">
										<view class="text-sm text-grey">
											今日下料
											<text v-if="today_feed_diff<=0"
												class="text-green">⬇{{Math.abs(today_feed_diff)}}%</text>
											<text v-if="today_feed_diff>0"
												class="text-orange">⬆{{Math.abs(today_feed_diff)}}%</text>
										</view>
										<view class="margin-top-sm text-xl ">{{today_feed}}
											<text class="text-grey margin-left-xs text-xs"> kg</text>
										</view>
									</view>
								</view>

							</view>
						</view>

						<view class="padding-xs">
							<view class="bg-pannel padding radius  shadow" hover-class="opcity" hover-stay-time="150">
								<view class="flex ">
									<view class="flex-sub flex align-center ">
										<i class="iconfont icon-water text-sl text-grey"></i>
									</view>

									<view class="flex-twice">
										<view class="text-sm text-grey">
											今日下水
											<text v-if="today_water_diff<=0"
												class="text-green">⬇{{Math.abs(today_water_diff)}}%</text>
											<text v-if="today_water_diff>0"
												class="text-orange">⬆{{Math.abs(today_water_diff)}}%</text>
										</view>
										<view class="margin-top-sm text-xl ">{{today_water}}
											<text class="text-grey margin-left-xs text-xs"> L</text>
										</view>
									</view>
								</view>

							</view>
						</view>

						<view class="padding-xs">
							<view class="bg-pannel padding radius  shadow" hover-class="opcity" hover-stay-time="150">
								<view class="flex ">
									<view class="flex-sub flex align-center ">
										<i class="iconfont icon-food text-sl text-grey"></i>
									</view>
									<view class="flex-twice">
										<view class="text-sm text-grey">昨日下料</view>
										<view class="margin-top-sm text-xl ">{{yestoday_feed}} <text
												class="text-grey margin-left-xs text-xs"> kg</text></view>
									</view>
								</view>

							</view>
						</view>

						<view class="padding-xs">
							<view class="bg-pannel padding radius  shadow" hover-class="opcity" hover-stay-time="150">
								<view class="flex ">
									<view class="flex-sub flex align-center ">
										<i class="iconfont icon-water text-sl text-grey"></i>
									</view>
									<view class="flex-twice">
										<view class="text-sm text-grey">昨日下水</view>
										<view class="margin-top-sm text-xl ">{{yestoday_water}} <text
												class="text-grey margin-left-xs text-xs">L</text></view>
									</view>
								</view>

							</view>
						</view>

						<view class="padding-xs">
							<view class="bg-pannel padding radius  shadow" hover-class="opcity" hover-stay-time="150">
								<view class="flex ">
									<view class="flex-sub flex align-center ">
										<i class="iconfont icon-pig2 text-sl text-grey"></i>
									</view>
									<view class="flex-twice">
										<view class="text-sm text-grey">猪只个数</view>
										<view class="margin-top-sm text-xl ">{{pig_num_total}} <text
												class="text-grey margin-left-xs text-xs">头</text></view>
									</view>
								</view>

							</view>
						</view>

						<view class="padding-xs">
							<view class="bg-pannel padding radius  shadow" hover-class="opcity" hover-stay-time="150">
								<view class="flex ">
									<view class="flex-sub flex align-center ">
										<i class="iconfont icon-pig2 text-sl text-grey"></i>
									</view>
									<view class="flex-twice">
										<view class="text-sm text-grey">仔猪个数</view>
										<view class="margin-top-sm text-xl ">{{son_total}} <text
												class="text-grey margin-left-xs text-xs">头</text></view>
									</view>
								</view>

							</view>
						</view>

						<view class="padding-xs">
							<view class="bg-pannel padding radius  shadow" hover-class="opcity" hover-stay-time="150">
								<view class="flex ">
									<view class="flex-sub flex align-center ">
										<i class="cuIcon-wifi text-xxxl text-grey"></i>
									</view>
									<view class="flex-twice">
										<view class="text-sm text-grey">在线/总设备</view>
										<view :class="online_num>0 && offline_num==0?'text-green':'text-orange'"
											class="margin-top-sm text-xl ">
											{{online_num}}/{{online_num+offline_num}}<text
												class="text-grey margin-left-xs text-xs"></text>
										</view>
									</view>
								</view>

							</view>
						</view>

						<view class="padding-xs">
							<view :class="alarm_num>0?'bg-alarm':''" class="bg-pannel padding radius  shadow"
								hover-class="opcity" hover-stay-time="150" @tap="onHouseAlarm()">
								<view class="flex ">
									<view class="flex-sub flex align-center ">
										<i class="cuIcon-notice text-xxxl "
											:class="{'text-grey': isNaN(alarm_num)||alarm_num==0,'text-red':alarm_num>0}"></i>
									</view>
									<view class="flex-twice">
										<view class="text-sm text-grey">告警</view>
										<view
											:class="{'': isNaN(alarm_num)||alarm_num==0,'text-red':alarm_num>0}"
											class="margin-top-sm text-xl ">{{alarm_num}} <text
												class="text-grey margin-left-xs text-xs"></text></view>
									</view>
								</view>

							</view>
						</view>

					</view>

					<view class=""></view>
					<view class="">
						<text class="padding-left text-sm text-grey">饲喂器在线率:</text>
					</view>

					<view class="padding-sm">
						<view class="flex padding-left-xs padding-right-xs">
							<view class=" cu-progress   ">
								<view v-if="online_per>40" :class="online_per>95?'bg-green':'bg-orange'"
									:style="[{ width: online_per+'%' }]">{{online_per}}%</view>
								<view v-if="online_per<=40" :class="online_per>10?'bg-red':'bg-black'"
									:style="[{ width: online_per+'%' }]">{{online_per}}%</view>
							</view>
						</view>
					</view>


					<view class="cu-bar solid-bottom">
						<view class="action">
							<text class="cuIcon-titles text-olive"></text><text class="text-grey ">日采食量总量</text>
						</view>
						<view class="action">
							<view class="">
								<button @tap="onTabDaySumFeedType('')" :class="DaySumFeedType==''?'':'line-grey'"
									class="cu-btn bg-olive shadow sm margin-right-xxs">全部</button>
								<button @tap="onTabDaySumFeedType('auto')"
									:class="DaySumFeedType=='auto'?'':'line-grey'"
									class="cu-btn bg-olive  shadow sm margin-right-xxs">智能</button>
								<button @tap="onTabDaySumFeedType('man')" :class="DaySumFeedType=='man'?'':'line-grey'"
									class="cu-btn bg-olive  shadow sm">手动</button>
							</view>
						</view>
					</view>
					<view style="height: 500rpx">
						<l-echart ref="chart"></l-echart>
					</view>


					<view class="cu-bar solid-bottom">
						<view class="action">
							<text class="cuIcon-titles text-olive"></text><text class="text-grey ">头均采食量</text>
						</view>
					</view>
					<view style="height: 500rpx">
						<l-echart ref="chart1"></l-echart>
					</view>
				</scroll-view>
			</block>

			<block v-if="TabCur==1">
				<view class="cu-bar search ">
					<view class="search-form round">
						<text class="cuIcon-search "></text>
						<input class="text-grey" @input="onKeyInput" @focus="InputFocus()" @blur="InputBlur()"
							:adjust-position="false" type="text" placeholder="栏位号/设备SN" confirm-type="search"
							v-model="inputValue"></input>
					</view>
					<view class="action">
						<view @tap="onScan()" class="flex justify-right text-xl">
							<text class="cuIcon-scan text-olive "></text>
						</view>
					</view>
				</view>

				<!-- <view class="">
					<view class="flex justify-left">
						<view class="padding-left">
							<text class='cuIcon-title text-blue'></text>
							<text class="text-xs text-grey">全部</text>
						</view>
					</view>
				</view> -->
				<view class="padding-left padding-right flex">

					<view class="flex-treble align-center">
						<button @tap="onTabNodeType('')" :class="node_type==''?'':'line-grey'"
							class="cu-btn bg-blue shadow sm margin-right-xxs">全部</button>
						<button @tap="onTabNodeType('online')" :class="node_type=='online'?'':'line-grey'"
							class="cu-btn bg-olive shadow sm margin-right-xxs">在线</button>
						<button @tap="onTabNodeType('offline')" :class="node_type=='offline'?'':'line-grey'"
							class="cu-btn bg-grey  shadow sm margin-right-xxs">离线</button>
						<button @tap="onTabNodeType('alarm')" :class="node_type=='alarm'?'':'line-grey'"
							class="cu-btn bg-red  shadow sm margin-right-xxs">告警</button>
					</view>
					<!-- <view class="flex-sub align-center justify-end text-right">
						<button 
							class="cu-btn bg-white  shadow sm margin-right-xxs"><text class="iconfont icon-cf-c17  padding-right-xs"></text>维护</button>
					</view> -->
				</view>

				<scroll-view scroll-y="true" class="scroll-Y padding-bottom-sm padding-top-sm"
					:style='{ height: nodeScrollHeight }'>
					<view class="">
						<block v-for="(item, idx) in nodeList" :key="idx">
							<view class="node-pannel margin-sm " hover-class="opcity" hover-stay-time="150"
								@tap="onTapFeedNode(item)">
								<view
									class="padding-top-xs padding-bottom-xs padding-left-sm padding-right-sm flex align-center">
									<view class="flex-sub  text-left">
										<text :class="item.online>0?'text-green':'text-grey'"
											class="iconfont icon-siweiqi"></text>
										<text :class="item.online<1?'text-grey':''"
											class=" padding-left-xs">{{item.hnum}}</text>
										
									</view>
									<view class="flex-sub  text-center">
										<text v-if="item.mode>0"
											class="  padding-left-xs">{{item.mode_day}}</text>
										<text v-if="item.mode==0" class="text-orange  padding-left-xs">停用</text>
									</view>
									<view class="flex-sub text-right flex justify-end align-center">
										<view v-if="item.model && item.model=='fg'" class="margin-left-xs cu-tag radius sm line-gray">粥料</view>
										<view v-if="item.has_water==1" class='cu-tag radius sm line-blue'>有水</view>
										<view v-if="item.has_water==0" class='cu-tag radius sm line-gray'>无水</view>
										<view v-if="item.alarm_bit0 && item.alarm_bit0>0" class='cu-tag radius sm line-orange'>堵料</view>
										<view v-if="item.alarm_bit1 && item.alarm_bit1>0" class='cu-tag radius sm line-orange'>堵水</view>
										<view v-if="item.alarm_bit2 && item.alarm_bit2>0" class='cu-tag radius sm line-orange'>探针</view>
										<view v-if="item.alarm_bit3 && item.alarm_bit3>0" class='cu-tag radius sm line-orange'>触碰</view>
										<view v-if="item.alarm_bit4 && item.alarm_bit4>0" class='cu-tag radius sm line-orange'>电机</view>
										<view v-if="item.alarm_bit5 && item.alarm_bit5>0" class='cu-tag radius sm line-orange'>下水</view>
										<view v-if="item.alarm_bit6 && item.alarm_bit6>0" class='cu-tag radius sm line-orange'>空转</view>

									
										<view v-if="item.online<1" class='cu-tag radius sm line-gray'>离线</view>

									</view>
								</view>

								<view
									class="padding-top-xs padding-bottom-xs padding-left-sm padding-right-sm flex align-center">
									<view class="flex-sub  text-left">
										<i class="iconfont icon-water text-lg text-grey"></i>
										<text class=" text-lg padding-left-xs">{{item.water}}</text>
										<text class="text-grey text-xs padding-left-xs">L</text>
									</view>
									<view class="flex-sub  text-center">
										<i class="iconfont icon-food text-lg text-grey"></i>
										<block v-if="item.model && item.model=='fg'">
											<text class=" text-lg padding-left-xs">{{item.feed}}</text>
										</block>
										<block v-if="!item.model || item.model=='feed' || item.model==''">
											<text v-if="item.mode!=3 && item.mode!=4" class=" text-lg padding-left-xs">{{item.feed}}/{{item.max_feed}}</text>
											<text v-if="item.mode==3 || item.mode==4" class=" text-lg padding-left-xs">{{item.feed}}</text>
										</block>
										
										<text class="text-grey text-xs padding-left-xs">kg</text>
									</view>
									<view class="flex-sub  text-right">
										<i class="iconfont  icon-pig2 text-lg text-grey"></i>
										<text class=" text-lg padding-left-xs">{{item.pig_num}}</text>
										<text v-if="item.mode==2" class="text-grey text-xs">+{{item.son}}仔</text>
										<text class="text-grey text-xs padding-left-xs"></text>
									</view>
								</view>


								<view
									class="padding-top-xs padding-bottom-xs padding-left-sm padding-right-sm flex align-center">
									<!-- <text class=" margin-right">{{item.per}}%</text> -->
									<view class=" cu-progress radius xs active">
										<view :class="item.per>95?'bg-green':'bg-orange'" class=""
											:style="[{ width: item.per+'%' }]"></view>

									</view>
									<text class=" margin-left">{{item.per}}%</text>
								</view>
							</view>
						</block>
					</view>

				</scroll-view>

				<view class="bottom-bar padding-top-sm">
					<view class="grid col-2 ">
						<view class="split padding-left-lg">
							<view @tap="showModal()" class="tab-alarm padding-sm shadow" hover-class="opcity"
								hover-stay-time="150">
								<view class="flex  align-center ">
									<view class="flex-sub text-center text-white">
										<i class="cuIcon-apps  "></i>
										<text class="padding-left-xs text-lg ">批量操作</text>
									</view>
								</view>
							</view>
						</view>

						<view class="padding-right-lg">
							<view @tap="loadRooms(true)" class="tab-notice padding-sm shadow" hover-class="opcity"
								hover-stay-time="150">
								<view class="flex  align-center ">
									<view class="flex-sub text-center text-white">
										<i class="cuIcon-refresh  "></i>
										<text class="padding-left-xs text-lg ">刷新</text>
									</view>
								</view>
							</view>
						</view>
					</view>
				</view>


				<view class="cu-modal bottom-modal" :class="showMenu?'show':''" @tap="hideModal">
					<view class="cu-dialog">
						<!-- <view class="cu-bar bg-white">
							<view class="action text-green" @tap="hideModal">确定</view>
							<view class="action text-grey" @tap="hideModal">取消</view>
						</view> -->
						<view class="">
							<view class="cu-list menu">
								<view v-if="edit_permission" class="cu-item arrow" @tap="onMenu('hnum')">
									<view class="content">
										<text class="iconfont icon-lan text-grey"></text>
										<text class="text-grey padding-left-xs">修改栏位号</text>
									</view>
								</view>
								<view v-if="manulfeed_permission" class="cu-item arrow" @tap="onMenu('feed')">
									<view class="content">
										<text class="iconfont icon-feed1 text-grey"></text>
										<text class="text-grey padding-left-xs">下料/下水</text>
									</view>
								</view>
		
								<view v-if="setparam_permission" class="cu-item arrow" @tap="onMenu('offset')">
									<view class="content">
										<text class="cuIcon-order text-grey"></text>
										<text class="text-grey">调整料量</text>
									</view>
								</view>
		
								<view v-if="setparam_permission" class="cu-item arrow" @tap="onMenu('calc')">
									<view class="content">
										<text class="cuIcon-focus text-grey"></text>
										<text class="text-grey">下料校准</text>
									</view>
								</view>
		
		
		
								<!-- <view class="cu-item arrow" @tap="onMenu('born')">
									<view class="content">
										<text class="cuIcon-female text-grey"></text>
										<text class="text-grey">一键分娩</text>
									</view>
								</view> -->
								<view v-if="setparam_permission" class="cu-item arrow" @tap="onMenu('day')">
									<view class="content">
										<text class="cuIcon-time text-grey"></text>
										<text class="text-grey">设置日龄</text>
									</view>
								</view>
								<view v-if="setparam_permission" class="cu-item arrow" @tap="onMenu('plan')">
									<view class="content">
										<text class="cuIcon-tag text-grey"></text>
										<text class="text-grey">应用方案</text>
									</view>
								</view>
								<view v-if="setparam_permission" class="cu-item arrow" @tap="onMenu('stop')">
									<view class="content">
										<text class="cuIcon-stop text-grey"></text>
										<text class="text-grey">停止饲喂</text>
									</view>
								</view>
							</view>


						</view>
					</view>
				</view>

			</block>

			<block v-if="TabCur==2">
				<scroll-view scroll-y="true" class="scroll-Y " :style='{ height: innerScrollHeight }'>
					<block v-for="(item, idx) in deviceList" :key="idx">

						<view :class="item.alive>0?'bg-online':'bg-offline'" class="device-pannel margin-sm "
							hover-class="opcity" hover-stay-time="150" @tap="onDeviceTap(item)">
							<view class="padding-sm flex align-center">
								<view class="flex-treble text-left">
									<text :class="item.alive>0?'text-grey':'text-grey'"
										class="iconfont icon-yingjian   "></text>
									<text :class="item.alive>0?'text-grey':'text-grey'"
										class=" text-icon-size  text-md padding-left-xs">{{item.housename}} </text>

								</view>
								<view class="flex-sub text-right justify-center">
									<view v-if="item.alive>0" class="">
										<text class="iconfont icon-zaixian2 text-olive"></text>
									</view>
									<view v-if="item.alive==0" class="">
										<text class="iconfont icon-lixian1 text-grey"></text>
									</view>
								</view>
							</view>
							<view class="padding-left padding-right flex align-center text-grey">
								<view class="flex-sub">
									<view class="fl text-xs  text-left">终端编码:</view>
								</view>
								<view class="flex-twice">
									<view class="fr text-xs ">
										{{item.device_addr}}
									</view>
								</view>
							</view>
							<view class="padding-left padding-right flex align-center text-grey">
								<view class="flex-sub">
									<view class="fl text-xs  text-left">饲喂器在线:</view>
								</view>
								<view class="flex-twice">
									<view class="fr text-xs " :class=" (item.node_num==0 || item.online_node_num<item.node_num)?'text-orange':'text-olive' ">
										{{item.online_node_num}}
									</view>
								</view>
							</view>
							<view class="padding-left padding-right flex align-center text-grey">
								<view class="flex-sub">
									<view class="fl text-xs  text-left">版本号:</view>
								</view>
								<view class="flex-twice">
									<view class="fr text-xs ">
										{{item.version}}
									</view>
								</view>
							</view>
							<view class="padding-left padding-right flex align-center text-grey">
								<view class="flex-sub">
									<view class="fl text-xs  text-left">饲喂器版本号:</view>
								</view>
								<view class="flex-twice">
									<view class="fr text-xs ">
										{{item.node_version}}
									</view>
								</view>
							</view>
							<view class="padding-left padding-right padding-bottom flex align-center text-grey">
								<view class="flex-sub">
									<view class="fl text-xs  text-left">最后心跳:</view>
								</view>
								<view class="flex-twice">
									<view class="fr text-xs ">
										{{item.lasttime}}
									</view>
								</view>
							</view>

							<view v-if="item.update" class="padding-left padding-right padding-bottom flex align-center text-orange">
								<view class="flex-sub">
									<view class="fl text-xs  text-left">升级饲喂器中:</view>
								</view>
								<view class="flex-twice">
									<view class="fr text-xs ">
										{{item.upStatus}}
									</view>
								</view>
							</view>

						</view>
					</block>

				</scroll-view>

				<view class="cu-modal bottom-modal" :class="showDeviceMenu?'show':''" @tap="hideDeviceModal">
					<view class="cu-dialog">
						<view class="">
							<view class="cu-list menu">
								<view v-if="is_admin" class="cu-item arrow" @tap="onUpdateGw()">
									<view class="content">
										<text class="iconfont icon-yingjian text-grey"></text>
										<text class="text-grey padding-left-xs">升级终端</text>
									</view>
								</view>
								<view v-if="is_admin" class="cu-item arrow" @tap="onUpdateNode()">
									<view class="content">
										<text class="iconfont icon-siweiqi text-grey"></text>
										<text class="text-grey padding-left-xs">升级饲喂器</text>
									</view>
								</view>
								
							</view>
		
		
						</view>
					</view>
				</view>
		
				<view class="cu-modal bottom-modal" :class="showFirmwareMenu?'show':''">
					<view class="cu-dialog">
						<view class="cu-bar bg-white">
							<view class="action text-grey" @tap="hideModalFirmware">取消</view>
							<view class="action text-green" @tap="onConfirmUpdate">确定</view>
						</view>
		
						<view class="padding flex justify-begin">
							<text class="iconfont icon-tishi1 text-green"></text>
							<text class="text-md text-grey text-sm">请选择固件后点击[确定]</text>
						</view>
		
						<view class="padding">
							<scroll-view scroll-y="true" class="scroll-Y " style="height: 500rpx;">
								<block v-for="(item, idx) in firmwareList" :key="idx">
									<view @tap="onFirmwareSelect(idx)" :class="item.select>0?'bg-select':'bg-unselect'"
										class=" margin-sm " hover-class="opcity" hover-stay-time="150">
										<view class="padding-sm flex align-center">
											<view class="flex-treble text-left">
												<text class=" text-grey padding-left-xs">{{item.name}}</text>
											</view>
											<view class="flex-sub text-right justify-center">
												<text class="text-grey">{{item.food_plan}}</text>
											</view>
										</view>
									</view>
								</block>
							</scroll-view>
						</view>
		
						<view class="padding">
		
						</view>
		
					</view>
				</view>

			</block>
		</scroll-view>
	</view>
</template>

<script>
	import cmdProgress from "@/components/cmd-progress/cmd-progress.vue"
	import * as api from 'common/api.js';
	const moment = require("../../common/moment.min.js");
	import * as echarts from '@/uni_modules/lime-echart/static/echarts.min'
	import * as util from '../../common/util.js'
	import {
		API_HEAD
	} from '../../common/api.js'

	const maskColor = "rgba(0, 0, 0, 0.2)";
	const redColor = "#FF3366";
	const greenColor = "#009900";
	const blueColor = "#009900";
	const grayColor = "#3e4144";
	const cyanColor = "#6ed0e0";
	const waterColor = "#00CCFF";
	const lightGreenColor = "#429c5e";
	const lightOrangeColor = "#f47011";
	const lightOrangeColor1 = "#eab839";
	const lightOrangeColor2 = "#ffee01";
	const co2Color = "#91c7ae";
	const gasColor = "#61a0a8";
	const titleColor = "#8f97b3";

	var chartDayAvgFeedOptions = {
		// backgroundColor: '#0e1a39',
		legend: {
			show: true,
			x: 'center',
			y: '10',
			icon: 'stack',
			itemWidth: 10,
			itemHeight: 10,
			textStyle: {
				fontSize: 11,
				color: 'rgb(0,253,255,0.6)'
			},
			data: ['下料量(kg)', "下水量(L)"]
		},
		tooltip: {
			trigger: 'axis',
			axisPointer: {
				lineStyle: {
					color: {
						type: 'linear',
						x: 0,
						y: 0,
						x2: 0,
						y2: 1,
						colorStops: [{
							offset: 0,
							color: 'rgba(0, 255, 233,0)'
						}, {
							offset: 0.5,
							color: 'rgba(255, 255, 255,1)',
						}, {
							offset: 1,
							color: 'rgba(0, 255, 233,0)'
						}],
						global: false
					}
				},
			}
		},
		grid: {
			top: '15%',
			left: '5%',
			right: '5%',
			bottom: '15%',
			containLabel: true
		},
		xAxis: [{
			type: 'category',
			axisLine: {
				show: true
			},
			splitArea: {
				// show: true,
				color: '#f00',
				lineStyle: {
					color: '#f00'
				},
			},
			axisLabel: {
				color: titleColor
			},
			splitLine: {
				show: false
			},
			boundaryGap: false,
			//data: ['A', 'B', 'C', 'D', 'E', 'F'],

		}],
		yAxis: [{
			type: 'value',
			min: 0,
			splitLine: {
				show: false,
				lineStyle: {
					color: 'rgba(255,255,255,0.1)'
				}
			},
			axisLine: {
				show: false,
			},
			axisLabel: {
				show: true,
				margin: 20,
				textStyle: {
					color: titleColor,
				},
				formatter: '{value} kg',
			},
			axisTick: {
				show: true,
			},
		}, {
			type: 'value',
			min: 0,
			splitLine: {
				show: true,
				lineStyle: {
					color: 'rgba(255,255,255,0.1)'
				}
			},
			axisLine: {
				show: false,
			},
			axisLabel: {
				show: true,
				margin: 20,
				textStyle: {
					color: titleColor,
				},
				formatter: '{value} L',
			},
			axisTick: {
				show: true,
			},
		}],
		series: [{
			name: '下料量(kg)',
			type: 'line',
			//symbolSize: 3,
			smooth: true, //是否平滑
			showSymbol: true,
			// symbol: 'image://./static/images/guang-circle.png',
			//symbol: 'none',
			yAxisIndex: 0,

			areaStyle: {
				normal: {
					color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
						offset: 0,
						color: lightOrangeColor
					}, {
						offset: 0.8,
						color: 'rgba(255,255,255,0)'
					}], false),
					// shadowColor: 'rgba(255,255,255, 0.1)',
					shadowBlur: 10,
					opacity: 0.3,
				}
			},
			itemStyle: {
				normal: {
					color: lightOrangeColor,
					lineStyle: {
						width: 1,
						type: 'solid' //'dotted'虚线 'solid'实线
					},
					borderColor: lightOrangeColor, //图形的描边颜色。支持的格式同 color
					//borderWidth: 8 ,//描边线宽。为 0 时无描边。[ default: 0 ]
					barBorderRadius: 0,
					label: {
						show: false,
					},
					opacity: 0.5,
				}
			},
			tooltip: {
				show: true
			}
		}, {
			name: '下水量(L)',
			type: 'line',
			smooth: true, //是否平滑
			showSymbol: true,
			yAxisIndex: 1,
			areaStyle: {
				normal: {
					color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
						offset: 0,
						color: '#00c7d9'
					}, {
						offset: 0.8,
						color: 'rgba(255,255,255,0)'
					}], false),
					// shadowColor: 'rgba(255,255,255, 0.1)',
					shadowBlur: 10,
					opacity: 0.3,
				}
			},
			itemStyle: {
				normal: {
					color: '#00c7d9',
					lineStyle: {
						width: 1,
						type: 'solid' //'dotted'虚线 'solid'实线
					},
					borderColor: '#00c7d9', //图形的描边颜色。支持的格式同 color
					//borderWidth: 8 ,//描边线宽。为 0 时无描边。[ default: 0 ]
					barBorderRadius: 0,
					label: {
						show: false,
					},
					opacity: 0.5,
				}
			},
			tooltip: {
				show: true
			}
		}]
	};
	var chartDaySumFeedOptions = {
		// backgroundColor: '#0e1a39',
		legend: {
			show: true,
			x: 'center',
			y: '10',
			icon: 'stack',
			itemWidth: 10,
			itemHeight: 10,
			textStyle: {
				fontSize: 11,
				color: 'rgb(0,253,255,0.6)'
			},
			//data: ['下料量(kg)', '下水量(L)'],
		},
		tooltip: {
			trigger: 'axis',
			axisPointer: {
				type: 'shadow'
			}
		},
		grid: {
			left: '3%',
			right: '4%',
			bottom: '15%',
			containLabel: true
		},
		xAxis: [{
			type: 'category',
			boundaryGap: true,
			data: [],
			splitLine: {
				show: true,
				lineStyle: {
					color: 'rgba(255,255,255,0.05)'
				}
			},
			axisLabel: {
				textStyle: {
					color: titleColor
				},
				//alignWithLabel: true,
				//interval: 0,
				//rotate: '15'
			}
		}],
		yAxis: [{
				type: 'value',
				splitLine: {
					show: true,
					lineStyle: {
						color: 'rgba(255,255,255,0.05)'
					}
				},
				axisLabel: {
					textStyle: {
						color: titleColor
					},
					formatter: '{value} kg',
				},
			},
			{
				type: 'value',
				splitLine: {
					show: true,
					lineStyle: {
						color: 'rgba(255,255,255,0.05)'
					}
				},
				axisLabel: {
					textStyle: {
						color: titleColor
					},
					formatter: '{value} L',
				},
			}
		],
		series: [{
				name: '下料量(kg)',
				type: 'bar',
				//barWidth: '10px',
				barMaxWidth: '10px',
				yAxisIndex: 0,
				data: [],
				itemStyle: {
					normal: {
						color: lightOrangeColor1,
						barBorderRadius: [30, 30, 30, 30],
						shadowColor: '#f29725',
						shadowBlur: 4,
					}
				},
			},
			{
				name: '下水量(L)',
				type: 'bar',
				//barWidth: '10px',
				barMaxWidth: '10px',
				yAxisIndex: 1,
				data: [],
				itemStyle: {
					normal: {
						color: waterColor,
						barBorderRadius: [30, 30, 30, 30],
						shadowColor: blueColor,
						shadowBlur: 4,
					}
				},
			},
			{
				name: '目标下料量(kg)',
				type: 'line',
				smooth: false, //是否平滑
				showSymbol: true,
				yAxisIndex: 0,
				itemStyle: {
					normal: {
						color: lightOrangeColor1,
						lineStyle: {
							width: 1,
							type: 'dotted' //'dotted'虚线 'solid'实线
						},
						borderColor: lightOrangeColor1, //图形的描边颜色。支持的格式同 color
						//borderWidth: 8 ,//描边线宽。为 0 时无描边。[ default: 0 ]
						barBorderRadius: 0,
						label: {
							show: false,
						},
						opacity: 0.5,
					}
				},
				tooltip: {
					show: true
				}
			}
		]
	};

	export default {
		data() {
			return {
				actions:[],
				edit_permission:false,
				delete_permission:false,
				setparam_permission:false,
				manulfeed_permission:false,
				is_admin:0,

				scrollHeight: 0,
				innerScrollHeight: 0,
				nodeScrollHeight: 0,
				TabCur: 0,
				loading: false,

				showMenu: false,
				showDeviceMenu:false,
				showFirmwareMenu:false,

				inputValue: '',
				node_type: '',

				farmname: '',
				farmid: '',
				housename: '',
				houseid: '',

				house: {},

				pig_num_total: '-',
				num_stop: '-',
				today_feed: '-',
				yestoday_feed: '-',
				today_water: '-',
				yestoday_water: '-',
				today_feed_diff: 0,
				today_water_diff: 0,
				online_num: 0,
				offline_num: 0,
				alarm_device_num: 0,
				alarm_num:0,
				son_total: '-',
				pig_num1: '-',
				pig_num2: '-',
				pig_num3: '-',
				pig_num4: '-',
				pig_num5: '-',
				house_num: '-',
				gw_num: '-',
				gw_alive_num: '-',
				gw_all_online: false,

				online_per: 0,

				DaySumFeedType: '',

				deviceList: [],

				nodeList: [],

				dayData: [],
				
				selectDevice:null,
				firmwareList:[],
			}
		},
		onReady() {
			// 计算scroll-view高度
			uni.getSystemInfo({
				success: resu => {
					//console.info("窗口高度:", resu.windowHeight)
					const query = uni.createSelectorQuery()
					query.select('.title').boundingClientRect()
					query.exec(res => {
						console.info("resu.windowHeight:", resu.windowHeight)
						console.info("顶部下拉区域:", res[0].height)
						this.scrollHeight = resu.windowHeight - res[0].height - 10 + 'px';
						this.innerScrollHeight = resu.windowHeight - res[0].height - 10 - 45 + 'px';
						this.nodeScrollHeight = resu.windowHeight - res[0].height - 10 - 45 - 50 - 24 -
							50 - 10 + 'px';
					})
				}
			})
		},
		onShow: function() {
			console.info("show house")
			uni.setNavigationBarTitle({
				title: this.housename
			});
		},
		created() {

		},
		onLoad(option) {
			console.info("load house", option)
			if (option.housename) {
				this.housename = option.housename
			}
			if (option.houseid) {
				this.houseid = option.houseid
			}
			if (option.farmname) {
				this.farmname = option.farmname
			}
			if (option.farmid) {
				this.farmid = option.farmid
			}
			if (this.houseid != '') {
				this.loadHouse()
				this.loadDayFeed()
			}

			var that = this
			getApp().getActions("/Device/FeedNodesNew").then(function(res){
				if (res.code >= 0) {
					that.actions = res.data
					that.edit_permission = false
					that.setparam_permission = false
					that.delete_permission = false
					that.manulfeed_permission =false
					for(var i=0;i<that.actions.length;i++){
						if(that.actions[i].action_id=='edit'){
							that.edit_permission = true
						}
						if(that.actions[i].action_id=='setparam'){
							that.setparam_permission = true
						}
						if(that.actions[i].action_id=='delete'){
							that.delete_permission = true
						}
						if(that.actions[i].action_id=='manulfeed'){
							that.manulfeed_permission = true
						}
					}
					//console.info(that.setparam_permission)
				}
			})

			var is_admin = getApp().isAdmin()
			that.is_admin = is_admin
			console.info("is_admin",is_admin)
			
		},
		methods: {
			onTabSelect(idx) {
				//console.info(idx)
				this.TabCur = idx
				if (this.TabCur == 0) {
					if (this.houseid != '') {
						this.loadHouse()
						this.loadDayFeed()
					}
				} else if (this.TabCur == 1) {
					this.loadRooms(true)
				} else if (this.TabCur == 2) {
					this.loadDevice()
				}
			},
			onTabNodeType(val) {
				this.node_type = val
				console.info("onTabNodeType", this.node_type)
				this.loadRooms(true)

			},
			onTabDaySumFeedType(val) {
				this.DaySumFeedType = val
				this.loadDayFeed()
			},
			onKeyInput(event) {
				this.inputValue = event.target.value
				console.info("inputValue", this.inputValue)
				this.loadRooms(true)
			},
			InputFocus() {

			},
			InputBlur() {

			},
			onTapFeedNode(item) {
				//console.info(JSON.stringify(item))
				uni.navigateTo({
					url: "/pages/feednode/feednode?addr=" + item.addr + "&sn=" + item.sn +
						"&hnum=" + item.hnum
				})
			},
			onScan() {
				var that = this
				uni.scanCode({
					scanType: ['qrCode'],
					success: function (res) {
						console.log('条码类型：' + res.scanType)
						console.log('条码内容：' + res.result)
						
						var code = res.result
						var idx = code.indexOf('MXCSWQ_')
						if(idx<0)
						{
							idx = code.indexOf('MXCZLQ_')
						}
						if (idx >= 0) {
							var sn_arr = code.split("_")
							if (sn_arr.length != 2) {
								uni.showModal({
									title: "错误的条码",
									content: "请扫码设备屏幕/标签上正确的条码",
									showCancel: false,
									confirmText: "确定"
								})
							} else {
								var sn = sn_arr[1]
								//判断sn是否有权限
						
								that.inputValue = sn
								that.loadRooms(true)
							}
						
						} else {
							uni.showModal({
								title: "错误的条码",
								content: "请扫码设备屏幕/标签上正确的条码",
								showCancel: false,
								confirmText: "确定"
							})
						}
					}
				});
			},
			showModal() {
				if(!this.setparam_permission && !this.edit_permission && !this.manulfeed_permission){
					uni.showToast({
						title: '您没有权限',
						icon: 'none'
					})
				}else{
					this.showMenu = true
				}
				
			},
			hideModal() {
				this.showMenu = false
			},
			onMenu(type) {
				console.info("onMenu", type)
				uni.navigateTo({
					url: "/pages/batch_op/batch_op?houseid=" + this.houseid + "&housename=" + this.housename+ "&op_type=" + type
				})
			},


			showDeviceModal() {
				if(!this.is_admin){
					uni.showToast({
						title: '您没有权限',
						icon: 'none'
					})
				}else{
					this.showDeviceMenu = true
				}
			},
			showFirmwareModal(type) {
				this.showFirmwareMenu = true
				this.loadFirmware(type)
			},
			hideDeviceModal(){
				console.info("hideDeviceModal")
				this.showDeviceMenu = false
			},
			hideModalFirmware(){
				console.info("hideDeviceModal")
				this.showFirmwareMenu = false
			},
			onDeviceTap(item){
				console.info(JSON.stringify(item))
				if(this.is_admin){
					this.selectDevice = item
					this.showDeviceModal();
				}else{
					console.info("无权限")
				}
			},
			onFirmwareSelect(idx) {
				console.info("onFirmwareSelect", idx)
				for (var i = 0; i < this.firmwareList.length; i++) {
					this.firmwareList[i].select = 0
				}
				this.firmwareList[idx].select = 1
				this.$forceUpdate()
			},

			loadHouse() {
				var that = this
				var token = getApp().getToken()
				api.myRequest({
					url: '/Api/House/SummaryInfo',
					method: 'GET',
					header: {
						'content-type': 'application/x-www-form-urlencoded',
						'Authorization': 'Bearer ' + token + ''
					},
					data: {
						id: that.houseid,
					},
				}, false).then(res => {
					if (res.code >= 0) {
						var list = res.data;
						if (list.length > 0) {
							var item = list[0];
							if (item.today_feed) {
								that.today_feed = parseFloat(item.today_feed.toFixed(1))
							} else {
								that.today_feed = 0
							}

							if (item.today_water) {
								that.today_water = parseFloat(item.today_water.toFixed(1))
							} else {
								that.today_water = 0
							}

							if (item.yestoday_water) {
								that.yestoday_water = parseFloat(item.yestoday_water.toFixed(1))
							} else {
								that.yestoday_water = 0
							}

							if (item.yestoday_feed) {
								that.yestoday_feed = parseFloat(item.yestoday_feed.toFixed(1))
							} else {
								that.yestoday_feed = 0
							}
							if (item.max_feed) {
								that.max_feed = parseFloat(item.max_feed.toFixed(1))
							} else {
								that.max_feed = 0
							}


							if (item.max_feed > 0) {
								that.feed_per = parseFloat(((item.today_feed / item.max_feed) *
									100).toFixed(1))
							} else {
								that.feed_per = 0
							}


							that.online_num = item.online_num | 0
							that.offline_num = item.offline_num | 0
							that.device_num = item.online_num + item.offline_num


							if (that.device_num > 0) {
								that.online_per = parseFloat(((item.online_num / that.device_num) * 100).toFixed(
									1))
							} else {
								that.online_per = 0
							}
							console.info(that.device_num, that.online_per)

							that.pig_num = item.pig_num | 0
							that.pig_num_total = item.pig_num_total | 0
							that.son_total = item.son_total | 0
							that.alarm_device_num = item.alarm_device_num | 0
							that.alarm_num = item.alarm_num | 0

							that.loadDayAvgFeed()
						}

					} else {

					}
				}).catch(err => {
					console.log(err)
				})
			},
			loadDayFeed() {

				var that = this
				var token = getApp().getToken()

				var begin = moment().add(-1, 'months').format('YYYY-MM-DD');
				var end = moment().add(-1, 'days').format('YYYY-MM-DD')

				that.loading = true
				api.myRequest({
					url: '/Api/House/DaySumFeed',
					method: 'GET',
					header: {
						'content-type': 'application/x-www-form-urlencoded',
						'Authorization': 'Bearer ' + token + ''
					},
					data: {
						id: that.houseid,
						begin: begin,
						end: end
					},
				}, false).then(res => {
					that.loading = false
					if (res.code >= 0) {

						that.dayData = res.data
						that.showChart1()
						that.showChart2()
					} else {

					}
				}).catch(err => {
					that.loading = false
					console.log(err)
				})
			},
			
			showChart1() {
				var that = this
				that.$refs.chart.init(echarts, chart => {
					var day_arr = [];
					var val_arr = [];
					var val1_arr = [];
					var max_arr = [];

					if (that.DaySumFeedType == "") {
						for (var i = 0; i < that.dayData.length; i++) {
							var his = that.dayData[i];
							var feed = parseFloat(his.day_use_feed_auto) + parseFloat(his.day_use_feed_man);
							var water = parseFloat(his.day_use_water_auto) + parseFloat(his.day_use_water_man);
							val_arr.push(feed.toFixed(2));
							val1_arr.push(water.toFixed(2));
							max_arr.push(parseFloat(his.max_feed.toFixed(2)));
							day_arr.push(moment(his.his_date).format("MM/DD"));
						}
						chartDaySumFeedOptions.series[0].data = val_arr;
						chartDaySumFeedOptions.series[1].data = val1_arr;
						chartDaySumFeedOptions.xAxis[0].data = day_arr;
						chartDaySumFeedOptions.series[0].name = "总下料量(kg)";
						chartDaySumFeedOptions.series[1].name = "总下水量(L)";
					} else if (that.DaySumFeedType == "auto") {
						for (var i = 0; i < that.dayData.length; i++) {
							var his = that.dayData[i];
							var feed = parseFloat(his.day_use_feed_auto);
							var water = parseFloat(his.day_use_water_auto);
							val_arr.push(feed.toFixed(2));
							val1_arr.push(water.toFixed(2));
							max_arr.push(parseFloat(his.max_feed.toFixed(2)));
							day_arr.push(moment(his.his_date).format("MM/DD"));
						}
						chartDaySumFeedOptions.series[0].data = val_arr;
						chartDaySumFeedOptions.series[1].data = val1_arr;
						chartDaySumFeedOptions.xAxis[0].data = day_arr;
						chartDaySumFeedOptions.series[0].name = "智能下料量(kg)";
						chartDaySumFeedOptions.series[1].name = "智能总下水量(L)";
					} else if (that.DaySumFeedType == "man") {
						for (var i = 0; i < that.dayData.length; i++) {
							var his = that.dayData[i];
							var feed = parseFloat(his.day_use_feed_man);
							var water = parseFloat(his.day_use_water_man);
							val_arr.push(feed.toFixed(2));
							val1_arr.push(water.toFixed(2));
							max_arr.push(parseFloat(his.max_feed.toFixed(2)));
							day_arr.push(moment(his.his_date).format("MM/DD"));
						}
						chartDaySumFeedOptions.series[0].data = val_arr;
						chartDaySumFeedOptions.series[1].data = val1_arr;
						chartDaySumFeedOptions.xAxis[0].data = day_arr;
						chartDaySumFeedOptions.series[0].name = "手动下料量(kg)";
						chartDaySumFeedOptions.series[1].name = "手动总下水量(L)";
					}


					chartDaySumFeedOptions.series[2].data = max_arr;
					setTimeout(function() {
						chart.setOption(chartDaySumFeedOptions);
						chart.resize()
					}, 200);
				})
			},
			showChart2() {
				var that = this
				that.$refs.chart1.init(echarts, chart1 => {
					var day_arr = [];
					var val_arr = [];
					var val1_arr = [];

					//console.info(res.data)
					for (var i = 0; i < this.dayData.length; i++) {
						var his = this.dayData[i];
						var feed = parseFloat(his.day_use_feed_auto) + parseFloat(his.day_use_feed_man);
						var water = parseFloat(his.day_use_water_auto) + parseFloat(his.day_use_water_man);
						var avg_feed = feed / his.pig_num
						var avg_water = water / his.pig_num
						val_arr.push(avg_feed.toFixed(2));
						val1_arr.push(avg_water.toFixed(2));
						day_arr.push(moment(his.his_date).format("MM/DD"));
					}


					chartDayAvgFeedOptions.series[0].data = val_arr;
					chartDayAvgFeedOptions.series[1].data = val1_arr;
					chartDayAvgFeedOptions.xAxis[0].data = day_arr;

					setTimeout(function() {
						chart1.setOption(chartDayAvgFeedOptions);
						chart1.resize();
					}, 200);
				})
			},
			loadDevice() {
				var that = this
				var token = getApp().getToken()
				that.loading = true
				api.myRequest({
					url: '/Api/Device',
					method: 'GET',
					header: {
						'content-type': 'application/x-www-form-urlencoded',
						'Authorization': 'Bearer ' + token + ''
					},
					data: {
						houseid: that.houseid
					},
				}, false).then(res => {
					that.loading = false
					if (res.code >= 0) {
						console.info(res)
						var list = res.data
						for(var i=0;i<list.length;i++){
							if(list[i].node_version){
								var arr = list[i].node_version.split(",")
								if(arr.length>1){
									//多个版本
									list[i].node_version = '多种';
								}else{

								}
							}


						}

						that.deviceList = list

						for(var i=0;i<list.length;i++){
							that.checkUpdateStatus(list[i])
						}

					} else {

					}
				}).catch(err => {
					that.loading = false
					console.log(err)
				})
			},
			loadRooms(show_load) {
				var that = this
				var token = getApp().getToken()

				var online = ''
				var alarm = ''
				if (that.node_type == "") {
					online = ''
					alarm = ''
				} else if (that.node_type == "online") {
					online = '1'
					alarm = ''
				} else if (that.node_type == "offline") {
					online = '0'
					alarm = ''
				} else if (that.node_type == "alarm") {
					online = ''
					alarm = '1'
				}

				if (show_load) {
					that.loading = true
				}
				api.myRequest({
					url: '/Api/Device/Feednode',
					method: 'GET',
					header: {
						'content-type': 'application/x-www-form-urlencoded',
						'Authorization': 'Bearer ' + token + ''
					},
					data: {
						houseid: that.houseid,
						device_type: 'DMXFGW',
						online: online,
						alarm: alarm,
						key: that.inputValue
					},
				}, false).then(res => {
					that.loading = false
					if (res.code >= 0) {
						//console.info(res)
						var list = res.data
						for (var i = 0; i < list.length; i++) {
							var mode_str
							if(!list[i].model || list[i].model=="feed"){
								mode_str = util.decodeModeNew(list[i].mode)
								if (list[i].mode == 0 || list[i].mode == 5) {
									list[i].mode_day = mode_str
								} else {
									list[i].mode_day = mode_str + ' ' + list[i].day + '天'
								}
							}else if(list[i].model && list[i].model=="fg"){
								mode_str = util.decodeFg(list[i].mode)
								if (list[i].mode == 0 || list[i].mode == 3) {
									list[i].mode_day = mode_str
								} else {
									list[i].mode_day = mode_str + ' ' + list[i].day + '天'
								}
							}
							

							list[i].day_use_water_auto = list[i].day_use_water_auto ? list[i].day_use_water_auto :
								0
							list[i].day_use_water_man = list[i].day_use_water_man ? list[i].day_use_water_man : 0
							list[i].day_use_feed_auto = list[i].day_use_feed_auto ? list[i].day_use_feed_auto : 0
							list[i].day_use_feed_man = list[i].day_use_feed_man ? list[i].day_use_feed_man : 0
							list[i].max_feed = list[i].max_feed ? list[i].max_feed : 0

							list[i].pig_num = list[i].pig_num ? list[i].pig_num : 0
							list[i].son = list[i].son ? list[i].son : 0

							var water = parseFloat(list[i].day_use_water_auto) + parseFloat(list[i]
								.day_use_water_man)
							list[i].water = parseFloat(water.toFixed(2).toString()).toString();

							var feed = parseFloat(list[i].day_use_feed_auto) + parseFloat(list[i].day_use_feed_man)
							var per = 0
							if (list[i].max_feed > 0) {
								per = parseFloat((feed / parseFloat(list[i].max_feed) * 100).toFixed(1))
							} else {
								per = 0
							}

							list[i].feed = parseFloat(feed.toFixed(2))
							list[i].per = per
							list[i].max_feed = parseFloat(list[i].max_feed)
							
							//判断有水无水
							var status =JSON.parse(list[i].status)
							var para =JSON.parse(list[i].para)
							if(status && para && status.Adval && para.CalADR){
								if(parseInt(para.CalADR)<parseInt(status.Adval)){
									list[i].has_water=0;
								}else if(parseInt(para.CalAD)>parseInt(status.Adval)){
									list[i].has_water=1;
								}else{
									list[i].has_water=0;
								}
							}

							//告警显示
							list[i].alarm_bit0 = util.getByteBit(list[i].alarm,0)
							list[i].alarm_bit1 = util.getByteBit(list[i].alarm,1)
							list[i].alarm_bit2 = util.getByteBit(list[i].alarm,2)
							list[i].alarm_bit3 = util.getByteBit(list[i].alarm,3)
							list[i].alarm_bit4 = util.getByteBit(list[i].alarm,4)
							list[i].alarm_bit5 = util.getByteBit(list[i].alarm,5)
							list[i].alarm_bit6 = util.getByteBit(list[i].alarm,6)
							list[i].alarm_bit7 = util.getByteBit(list[i].alarm,7)
							list[i].alarm_bit8 = util.getByteBit(list[i].alarm,8)
							
						}
						that.nodeList = list

					} else {

					}
				}).catch(err => {
					that.loading = false
					console.log(err)
				})
			},
			onHouseAlarm() {
				uni.navigateTo({
					url: "/pages/alarm/alarm?farmname=" + this.farmname + "&farmid=" + this.farmid +
						"&housename=" + this.housename + "&houseid=" + this.houseid
				})
			},
			loadFirmware(type){

				var that = this
				var token = getApp().getToken()
				that.loading = true
				api.myRequest({
					url: '/Api/Firmware',
					method: 'GET',
					header: {
						'content-type': 'application/x-www-form-urlencoded',
						'Authorization': 'Bearer ' + token + ''
					},
					data: {},
				}, false).then(res => {
					that.loading = false
					if (res.code >= 0) {

						var firmwares =res.data
						var matchs=[];
						for(var i=0;i<firmwares.length;i++){
							if(firmwares[i].type==type){
								matchs.push(firmwares[i])
							}
						}

						that.firmwareList = matchs

					} else {

					}
				}).catch(err => {
					that.loading = false
					console.log(err)
				})
			},
			onUpdateGw(){
				this.hideDeviceModal()
				this.showFirmwareModal('Gw')
			},
			onUpdateNode(){
				this.hideDeviceModal()
				this.showFirmwareModal('Gw_NODE')
			},
			onConfirmUpdate(){
				//
				var that = this
				var idx = -1
				for (var i = 0; i < that.firmwareList.length; i++) {
					if (that.firmwareList[i].select == 1) {
						idx = i
						break
					}
				}
				if (idx < 0) {
					//that.hideModalPlan()
					console.info("idx:未选择", idx)
					uni.showToast({
						title: '请先选择固件',
						icon: 'error'
					})
				}else{
					var firmware = that.firmwareList[idx]
					
					that.hideModalFirmware()
					that.doUpdate(firmware)
				}
			},
			doUpdate(firmware){
				var that = this
				var url = ''
				if(firmware.type=="Gw"){
					url='/Api/Device/Gw/Update'
				}else if(firmware.type=="Gw_NODE"){
					url='/Api/Device/Gw/UpdateNode'
				}
				console.info("firmware:",JSON.stringify(firmware))
				console.info("device:",JSON.stringify(that.selectDevice))
				uni.showModal({
					title: '提示',
					content: '请注意,您即将对' + that.selectDevice.remark + '升级固件:' + firmware.name +' ,您的操作将会被系统记录',
					success: function(res) {
						if (res.confirm) {
							console.log('用户点击确定');
							var token = getApp().getToken()
							that.loading = true
							api.myRequest({
								url: url,
								method: 'PUT',
								header: {
									'content-type': 'application/x-www-form-urlencoded',
									'Authorization': 'Bearer ' + token + ''
								},
								data: {
									addr: that.selectDevice.device_addr,
									type: firmware.type,
									device_type: firmware.type,
									id:firmware.id,
									filename: firmware.name,
								},
							}, false).then(res => {
								that.loading = false
								if (res.code >= 0) {
									uni.showToast({
										title: '操作成功',
										icon: 'success',
										duration: 2000
									});
									setTimeout(function() {
										that.loadDevice()
									}, 5 * 1000)
								} else {
									uni.showModal({
										title: '失败',
										content: res.msg,
										showCancel: false
									})
								}
							}).catch(err => {
								that.loading = false
								console.log(err)
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			checkUpdateStatus(item){
				var that = this
				var token = getApp().getToken()
				api.myRequest({
					url: '/Api/Device/Gw/UpdateStatus',
					method: 'GET',
					header: {
						'content-type': 'application/x-www-form-urlencoded',
						'Authorization': 'Bearer ' + token + ''
					},
					data: {
						addr: item.device_addr
					},
				}, false).then(res => {
					if (res.code >= 0) {
						var update = false
						var str = ""
						if(res.data){
							if(res.data.Ug_State){
								update = true
								
								str+=(" 数据包:"+res.data.Ug_pkg+"/"+res.data.Ug_Tpkg);
								str+=(" 饲喂器序号:"+res.data.Ug_tn);
							}
						}
						for(var i=0;i<that.deviceList.length;i++){
							if(that.deviceList[i].device_addr == item.device_addr){
								that.deviceList[i].upStatus = str
								that.deviceList[i].update = update
								this.$forceUpdate()
								break
							}
						}
					} else {

					}
				}).catch(err => {
					
					console.log(err)
				})
			},
		}
	}
</script>

<style>
	.bg-pannel {
		min-height: 180rpx;
		border-radius: 5rpx;
		/* opacity: 0.9; */
		/* background: url("https://www.hozenn.com/iot/img/house.png") 80% 50% / 40% no-repeat linear-gradient(to top, rgba(255, 255, 255, 0.95)); */
		/* background-image:linear-gradient(to top, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0)),url('https://www.hozenn.com/iot/img/house.png'); */
		background-repeat: no-repeat;
		background-size: 20%;
		background-position: 55% 50%;
		background-color: rgba(230, 230, 230, 0.3);
		box-shadow: 0 2px 4px rgba(100, 100, 155, 0.5);
	}

	.device-pannel {
		min-height: 180rpx;
		border-radius: 5rpx;
		/* opacity: 0.9; */
		/* background: url("https://www.hozenn.com/iot/img/house.png") 80% 50% / 40% no-repeat linear-gradient(to top, rgba(255, 255, 255, 0.95)); */
		/* background-image:linear-gradient(to top, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0)),url('https://www.hozenn.com/iot/img/house.png'); */
		background-repeat: no-repeat;
		background-size: 20%;
		background-position: 55% 50%;
		background-color: rgba(230, 230, 230, 0.6);
		box-shadow: 0 2px 4px rgba(100, 100, 155, 0.5);
	}
	
	.bg-online {
		background-color: rgba(230, 230, 230, 0.6);
		/* border: 1px solid #0d8400; */
	}
	
	.bg-offline {
		background-color: rgba(230, 230, 230, 0.6);
		/* border: 1px solid #878787; */
	}

	.node-pannel {
		min-height: 180rpx;
		border-radius: 10rpx;
		/* opacity: 0.9; */
		/* background: url("https://www.hozenn.com/iot/img/house.png") 80% 50% / 40% no-repeat linear-gradient(to top, rgba(255, 255, 255, 0.95)); */
		/* background-image:linear-gradient(to top, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0)),url('https://www.hozenn.com/iot/img/house.png'); */
		/* background-repeat: no-repeat; */
		/* background-size: 20%; */
		/* background-color: rgba(230, 230, 230, 0.2); */
		border: 1px solid rgba(200, 200, 200, 0.9);
		box-shadow: 0 2px 4px rgba(100, 100, 100, 0.3);
	}

	.bg-alarm {
		background-color: rgba(255, 96, 48, 0.5);
		/* border: 1px solid #e54d42; */
	}

	

	.split {
		border-right: 1px solid #eaeaea;
	}

	.opcity {
		opacity: 0.8;
	}

	.cu-modal{
		z-index: 2;
	}

	.cu-bar .search-form {
		background-color: rgba(100, 100, 100, 0.1);
	}

	.bottom-bar {
		height: 50px;
		border-top: 1px solid #aaa;
		/* background-color: aliceblue; */
		/* border-top:1px solid #878787; */
	}

	.tab-alarm {
		/* min-height: 180rpx; */
		background-color: #3c7cff;
		height: 40px;
		border-radius: 20px 00% 0% 20px;
		/* border: 1px solid #e54d42; */
	}

	.tab-notice {
		/* min-height: 180rpx; */
		background-color: #3c7cff;
		height: 40px;
		border-radius: 0px 20px 20px 0px;
		/* border: 1px solid #e54d42; */
	}

	.bg-select {
		background-color: rgba(200, 200, 200, 0.3);
		border: 2px solid #0d8400;
		border-radius: 5px;
	}

	.bg-unselect {
		background-color: rgba(200, 200, 200, 0.3);
		border: 1px solid #dadada;
		border-radius: 5px;
	}
</style>